"""Build management server module"""
import daos_build

def scons():
    """Execute build"""
    Import('env', 'prereqs')

    env.AppendUnique(LIBPATH=[Dir('.')])

    denv = env.Clone()

    denv.AppendUnique(CPPPATH=[Dir('.').srcnode()])

    prereqs.require(denv, 'protobufc', 'hwloc')

    #pylint: disable=invalid-name
    pb = denv.SharedObject(['acl.pb-c.c', 'pool.pb-c.c', 'svc.pb-c.c',
                            'smd.pb-c.c', 'cont.pb-c.c', 'server.pb-c.c'])
    #pylint: enable=invalid-name
    common = denv.SharedObject(['rpc.c']) + pb

    # Management client library
    dc_mgmt_tgts = common + denv.SharedObject(['cli_mgmt.c', 'cli_query.c',
                                               'cli_debug.c'])
    Export('dc_mgmt_tgts')

    if not prereqs.server_requested():
        return

    senv = denv.Clone()
    prereqs.require(senv, 'protobufc', 'hwloc')
    prereqs.require(senv, 'argobots', 'pmdk', headers_only=True)
    # Management server module
    senv.Append(CPPDEFINES=['-DDAOS_PMEM_BUILD'])
    mgmt_srv = daos_build.library(senv, 'mgmt',
                                  [common, 'srv.c', 'srv_layout.c',
                                   'srv_pool.c', 'srv_system.c',
                                   'srv_target.c', 'srv_query.c',
                                   'srv_drpc.c', 'srv_util.c',
                                   'srv_container.c'], install_off='../..')
    senv.Install('$PREFIX/lib64/daos_srv', mgmt_srv)

    denv = senv
    SConscript('tests/SConscript', exports=['denv', 'pb'])

if __name__ == "SCons.Script":
    scons()
